package com.md.mod.service.imp;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.md.mod.bean.SysUser;
import com.md.mod.dao.SysUserMapper;
import com.md.mod.service.UserService;
import com.md.mod.utils.JSONResult;
import com.mysql.jdbc.StringUtils;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.io.Serializable;
import java.util.List;

/**
 * ********************************
 *
 * @author zhaoqingwei.
 * 天下英雄出我辈，一入江湖岁月催.
 * 20192019/1/2822:49
 * ********************************
 * 描述：
 * <p>
 * 注释：
 **/

@Service("iUserService")
public class IUserService implements UserService,Serializable {
    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public JSONResult selectUserListPage(SysUser user, Integer pagenum, Integer pageSize) {
        //开始分页
        Page page = PageHelper .startPage(pagenum,pageSize);
        Example example = new Example(SysUser.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isEmptyOrWhitespaceOnly(user.getNickname())){
            criteria.andLike("username","%"+user.getUsername()+"%");
        }
        example.orderBy("username").desc();

        List<SysUser> users = sysUserMapper.selectByExample(example);
        return JSONResult.JSONPage(users,page);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void saveUser(SysUser user) throws Exception {
        sysUserMapper.insert(user);
        int b = 1/0;
        sysUserMapper.delete(user);
        System.out.println(sysUserMapper);
    }

    @Override
    public SysUser selectOne(SysUser user) {
        return sysUserMapper.selectOne(user);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int deleteByPrimaryKey(Object key) {
        return 0;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int delete(SysUser record) {
        return 0;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int insert(SysUser record) {
        return 0;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int insertSelective(SysUser record) {
        return 0;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public boolean existsWithPrimaryKey(Object key) {
        return false;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<SysUser> selectAll() {
        return null;
    }

    @Override
    public SysUser selectByPrimaryKey(Object key) {
        return null;
    }

    @Override
    public int selectCount(SysUser record) {
        return 0;
    }

    @Override
    public List<SysUser> select(SysUser record) {
        return null;
    }

    @Override
    public int updateByPrimaryKey(SysUser record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKeySelective(SysUser record) {
        return 0;
    }

    @Override
    public int deleteByExample(Object example) {
        return 0;
    }

    @Override
    public List<SysUser> selectByExample(Object example) {
        return null;
    }

    @Override
    public int selectCountByExample(Object example) {
        return 0;
    }

    @Override
    public SysUser selectOneByExample(Object example) {
        return null;
    }

    @Override
    public int updateByExample(SysUser record, Object example) {
        return 0;
    }

    @Override
    public int updateByExampleSelective(SysUser record, Object example) {
        return 0;
    }

    @Override
    public List<SysUser> selectByExampleAndRowBounds(Object example, RowBounds rowBounds) {
        return null;
    }

    @Override
    public List<SysUser> selectByRowBounds(SysUser record, RowBounds rowBounds) {
        return null;
    }

    @Override
    public int insertList(List<SysUser> recordList) {
        return 0;
    }

    @Override
    public int insertUseGeneratedKeys(SysUser record) {
        return 0;
    }
}
